﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenMinded.IDAL;
using System.Data;
using OpenMinded.DBUtility;
using System.Data.SqlClient;

namespace OpenMinded.SQLServerDAL
{
    public class Users : IUsers
    {
        //静态变量
        private const string SQL_SELECT_USE = "SELECT * FROM USERS WHERE LoginId=@LoginId";
        private const string LOGIN_ID = "@LoginId";
        /// <summary>
        /// 获得一个用户实体
        /// </summary>
        /// <param name="loginId">登录名</param>
        /// <returns>返回一个用户实例</returns>
        public Model.Users GetUser(string loginId)
        {
            Model.Users user = null;
            SqlParameter par = new SqlParameter(LOGIN_ID, SqlDbType.NVarChar, 50);
            par.Value = loginId;
            using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USE, par))
            {
                if (dr.Read())
                    user = new Model.Users(dr.GetInt32(0), dr.GetString(1), dr.GetString(4));
            }
            return user;
        }
    }
}
